package gowcage.testmap;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.View;

/**
 * Created by Administrator on 2017/11/14.
 */

public class MapView extends View {

    String TAG = "MapView-->";

    int blockSize = 30, borderSize = 10;

    Paint paint;

    int[][] map = {
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
            {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 8},
            {0, 8, 8, 8, 8, 8, 8, 8, 8, 1, 8, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 1, 8, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 1, 8},
            {0, 8, 1, 1, 1, 1, 1, 1, 8, 1, 8, 0, 0, 8, 1, 1, 1, 1, 1, 1, 8, 1, 8, 0, 0, 8, 1, 1, 1, 1, 1, 1, 8, 1, 8},
            {0, 8, 1, 8, 8, 8, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 8, 8, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 8, 8, 8, 1, 8, 1, 8},
            {0, 8, 1, 8, 1, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 1, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 1, 1, 8, 1, 8, 1, 8},
            {0, 8, 1, 8, 1, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 1, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 1, 1, 8, 1, 8, 1, 8},
            {0, 8, 1, 8, 8, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 8, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 8, 8, 1, 8, 1, 8, 1, 8},
            {0, 8, 1, 1, 1, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 1, 1, 1, 8, 1, 8, 1, 8, 0, 0, 8, 1, 1, 1, 1, 8, 1, 8, 1, 8},
            {0, 8, 8, 8, 8, 8, 8, 1, 8, 8, 8, 0, 0, 8, 8, 8, 8, 8, 8, 1, 8, 8, 8, 0, 0, 8, 8, 8, 8, 8, 8, 1, 8, 8, 8},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    };

    public MapView(Context context) {
        super(context);
        paint = new Paint();
    }

    public void paint(Canvas c, Paint p) {//画地图
        p.setColor(Color.YELLOW);
        long s = System.currentTimeMillis();
        for (int i = 0; i < map.length; i++) {
            for (int j = 0; j < map[i].length; j++) {
                if (map[i][j] == 0) {
                    p.setColor(Color.BLACK);
                    c.drawRect(j * blockSize, i * blockSize, j * blockSize + borderSize, i * blockSize + borderSize, p);
                }
                if (map[i][j] == 8) {
                    p.setColor(Color.YELLOW);
                    c.drawRect(j * blockSize, i * blockSize, j * blockSize + blockSize, i * blockSize + blockSize, p);
                }
                if (map[i][j] == 1) {
                    p.setColor(Color.GRAY);
                    c.drawRect(j * blockSize, i * blockSize, j * blockSize + blockSize, i * blockSize + blockSize, p);
                }
            }
        }
        Log.d(TAG, "time:" + (System.currentTimeMillis() - s));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint(canvas, paint);
    }
}
